/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://gitee.com/shenyczz/csharp_csk
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/

using System;
using System.Runtime.InteropServices;

using codes_index = System.IntPtr;


namespace CSharpKit.Native.ECCODES
{
    // \defgroup codes_index The indexing feature
    // The codes_index is the structure giving indexed access to messages in a file.
    partial class eccodes
    {
        /// <summary>
        /// 原型: codes_index* codes_index_new_from_file(codes_context* c, const char* filename, const char* keys, int* err) <br/>
        /// 功能:  <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_context">codes_context* c, default = 0</param>
        /// <param name="fname">name of the file of messages to be indexed</param>
        /// <param name="keys">
        ///     comma separated list of keys for the index. (索引的逗号分隔键列表) 
        ///     The type of the key can be explicitly declared appending :l for long,(or alternatively :i)
        ///     :d for double, :s for string to the key name. If the type is not
        ///     declared explicitly, the native type is assumed.
        /// </param>
        /// <param name="err">0 if OK, integer value on error</param>
        /// <returns> the newly created index : codes_index_ptr </returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_new_from_file")]
        public extern static IntPtr codes_index_new_from_file(IntPtr codes_context, string fname, string keys, out int err);

        /// <summary>
        /// <para>功能: Create a new index based on a set of keys.</para>
        /// <para>说明: </para>
        /// </summary>
        /// <param name="context"> </param>
        /// <param name="keys">comma separated list of keys for the index. 
        /// The type of the key can be explicitly declared appending 
        ///     :l for long,(or alternatively :i)
        ///     :d for double
        ///     :s for string to the key name
        /// If the type is not declared explicitly, the native type is assumed.
        /// </param>
        /// <param name="err">0 if OK, integer value on error </param>
        /// <returns>the newly created index </returns>
        /// <remarks>
        /// 原型: codes_index* codes_index_new(codes_context* c, const char* keys, int* err)
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_new")]
        public extern static IntPtr codes_index_new(IntPtr context, string keys, IntPtr err);


        /// <summary>
        /// <para>功能: Indexes the file given in argument in the index given in argument.</para>
        /// <para>说明: </para>
        /// </summary>
        /// <param name="index"> </param>
        /// <param name="filename">name of the file of messages to be indexed </param>
        /// <returns> 0 if OK, integer value on error</returns>
        /// <remarks>
        /// 原型: int codes_index_add_file(codes_index* index, const char* filename)
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_add_file")]
        public extern static int codes_index_add_file(IntPtr index, string filename);


        /// <summary>
        /// 原型: int codes_index_write(codes_index* index, const char* filename); <br/>
        /// 功能:  <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_write")]
        public extern static int codes_index_write(IntPtr codes_index, string filename);

        /// <summary>
        /// 原型: codes_index* codes_index_read(codes_context* c, const char* filename, int* err); <br/>
        /// 功能:  <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filename"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_read")]
        public extern static IntPtr codes_index_read(IntPtr context, string filename, IntPtr err);


        /// <summary>
        /// 原型: int codes_index_get_size(const codes_index* index, const char* key, size_t* size); <br/>
        /// 功能: Get the number of distinct values of the key in argument contained in the index. The key must belong to the index.<br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index">an index created from a file.The index must have been created with the key in argument.</param>
        /// <param name="key"> key for which the number of values is computed </param>
        /// <param name="size"> number of distinct values of the key in the index </param>
        /// <returns> 0 if OK, integer value on error </returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_get_size")]
        public extern static int codes_index_get_size(IntPtr codes_index, string key, ref int size);

        /// <summary>
        /// 原型: int codes_index_get_long(const codes_index* index, const char* key, long* values, size_t* size); <br/>
        ///   The key must belong to the index. 
        ///   This function is used when the type of the key was explicitly defined as long or when the native type of the key is long.<br/>
        /// 功能: Get the distinct values(非重复值) of the key in argument contained in the index. <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index"> an index created from a file. The index must have been created with the key in argument. </param>
        /// <param name="key">key for which the values are returned </param>
        /// <param name="values">array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. </param>
        /// <param name="size">size of the values array </param>
        /// <returns>0 if OK, integer value on error</returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_get_long")]
        public extern static int codes_index_get_long(IntPtr codes_index, string key, ref long[] values, ref int size);


        /// <summary>
        /// 原型: int codes_index_get_double(const codes_index* index, const char* key, double* values, size_t* size); <br/>
        /// 功能: Get the distinct values of the key in argument contained in the index. The key must belong to the index. 
        ///   This function is used when the type of the key was explicitly defined as double or when the native type of the key is double.<br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index"> an index created from a file. The index must have been created with the key in argument. </param>
        /// <param name="key"> key for which the values are returned </param>
        /// <param name="values"> array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. </param>
        /// <param name="size"> size of the values array </param>
        /// <returns>0 if OK, integer value on error</returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_get_double")]
        public extern static int codes_index_get_double(IntPtr codes_index, string key, ref long[] values, ref int size);



        /**
         *  Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly defined as string or when the native type of the key is string.
         *
         * @param index       : an index created from a file.
         *     The index must have been created with the key in argument.
         * @param key         : key for which the values are returned
         * @param values      : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
         * @param size        : size of the values array
         * @return            0 if OK, integer value on error
         */
        /// <summary>
        /// 原型: int codes_index_get_string(const codes_index* index, const char* key, char** values, size_t* size); <br/>
        /// 功能:  <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="index"> </param>
        /// <param name="key"> </param>
        /// <param name="values"> </param>
        /// <param name="size"> </param>
        /// <returns></returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_get_string")]
        public extern static int codes_index_get_string(codes_index index, string key, ref string[] values, ref int size);




        /// <summary>
        /// 原型: int codes_index_select_long(codes_index* index, const char* key, long value); 
        ///   The value is a long. The key must have been created with long type or have long as native type if the 
        ///   type was not explicitly defined in the index creation.<br/>
        /// 功能: Select the message subset with key==value.  <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index"> an index created from a file. The index must have been created with the key in argument. </param>
        /// <param name="key"> key to be selected </param>
        /// <param name="value"> value of the key to select </param>
        /// <returns> 0 if OK, integer value on error </returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_select_long")]
        public extern static int codes_index_select_long(IntPtr codes_index, string key, long value);

        /// <summary>
        /// 原型: int codes_index_select_double(codes_index* index, const char* key, double value); <br/>
        /// 功能: Select the message subset with key==value.  <br/>
        ///   The value is a long. The key must have been created with long type or have long as native type if the 
        ///   type was not explicitly defined in the index creation.<br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="codes_index"> an index created from a file. The index must have been created with the key in argument. </param>
        /// <param name="key"> key to be selected </param>
        /// <param name="value"> value of the key to select </param>
        /// <returns> 0 if OK, integer value on error </returns>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_select_double")]
        public extern static int codes_index_select_double(codes_index codes_index, string key, double value);


        /**
         * int codes_index_select_string(codes_index* index, const char* key, const char* value);
         *
         * Select the message subset with key==value. The value is a string. The key must have been created with string type or have string as native type if the type was not explicitly defined in the index creation.
         *
         * @param index       : an index created from a file.
         *     The index must have been created with the key in argument.
         * @param key         : key to be selected
         * @param value       : value of the key to select
         * @return            0 if OK, integer value on error
         */
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_select_string")]
        public extern static int codes_index_select_string(codes_index index, string key, double value);


        /**
         *  void codes_index_delete(codes_index* index);
         *
         *  Delete the index.
         * @param index       : index to be deleted.
         */
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_index_delete")]
        public extern static int codes_index_delete(IntPtr codes_index);


        /// <summary>
        /// 原型: codes_handle* codes_handle_new_from_index(codes_index* index, int* err); <br/>
        /// 功能: Create a new handle from an index after having selected the key values. <br/>
        /// 状态:  <br/>
        /// </summary>
        /// <param name="index"> an index created from a file. </param>
        /// <param name="err"> 0 if OK, integer value on error. CODES_END_OF_INDEX when no more handles are contained in the index. </param>
        /// <returns> GRIB handle. </returns>
        /// <remarks>
        /// All the keys belonging to the index must be selected before calling this function. Successive calls to this function will return all the handles compatible with the constraints defined selecting the values of the index keys.
        /// When no more handles are available from the index a NULL pointer is returned and the err variable is set to CODES_END_OF_INDEX.
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_handle_new_from_index")]
        public extern static IntPtr codes_handle_new_from_index(codes_index index, out int err);
        

        // {{END}}
    }


}
